package test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class NextBirthday {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        //int year,m,day
        Calendar calendar1 = Calendar.getInstance();    //现在的时间
        calendar1.set(Calendar.HOUR,0);
        calendar1.set(Calendar.MINUTE,1);
        calendar1.set(Calendar.SECOND,1);
        calendar1.set(Calendar.MILLISECOND,1);

        System.out.println(calendar1.getTime());
        int year=calendar1.get(Calendar.YEAR);
        Calendar calendar2 = Calendar.getInstance();    //生日的时间
        calendar2.set(Calendar.HOUR,0);
        calendar2.set(Calendar.MINUTE,1);
        calendar2.set(Calendar.SECOND,1);
        calendar2.set(Calendar.MILLISECOND,1);
        SimpleDateFormat a = new SimpleDateFormat("yyyy-MM-dd");
        a.setLenient(false);
        System.out.print("请输入生日（月-日格式）：");
        String birthday = input.next();

        //根据年，获得下一个生日日期，而且还是合法的。。。允许错8次
        int i=1;
        for(;i<=8;i++){
            String ys=year+"-"+birthday;
            try {
                Date date = a.parse(ys);
                calendar2.setTime(date);
               if(calendar1.before(calendar2)){
               // if(calendar1.getTime().getTime()/1000<=calendar2.getTime().getTime()/1000){
                    break;
                }
                year++;
            } catch (ParseException e) {
                //e.printStackTrace();
                year++;
            }
        }
        if(i>8){
            System.out.println("生日有问题！输入错误");
            return;
        }
        System.out.println("下一个生日:"+calendar2.getTime());

    }
}
